<template>
  <div>
    <el-card style="margin-top:20px;">
      <h3>订单管理</h3>
      <el-row style="margin-top:10px;">
        <el-select v-model="searchWay" placeholder="按订单号查询">
          <el-option label="按订单号查询" value="orderNo"></el-option>
          <el-option label="按用户名查找" value="query"></el-option>
        </el-select>
        <el-input style="width:140px;" v-model="queryInfo.orderNo" placeholder="请输入内容"></el-input>
        <el-button type="primary" @click="search">搜索</el-button>
      </el-row>
      <el-table :data="list" stripe style="width: 100%">
        <el-table-column prop="orderNo" label="订单号" width="180"></el-table-column>
        <el-table-column prop="receiverName" label="收件人" width="180"></el-table-column>
        <el-table-column prop="statusDesc" label="订单状态" width="180"></el-table-column>
        <el-table-column label="订单总价" width="180">
            <template slot-scope="scope">
                ￥{{scope.row.payment}}
            </template>
        </el-table-column>
        <el-table-column prop="createTime" label="创建时间" width="180"></el-table-column>
        <el-table-column label="操作" width="180">
            <template slot-scope="scope">
                <el-button @click="check(scope.row)">查看</el-button>
            </template>
        </el-table-column>
      </el-table>
      <pagination :total='total' @changeNum='changeNum' @changeSize='changeSize' ></pagination>
    </el-card>
  </div>
</template>

<script>
import { orderList } from "../util/http";
import { orderSearch } from "../util/http";
import pagination from '../components/pagination'
export default {
  // 组件名称
  name: "demo", // 组件参数 接收来自父组件的数据
  props: [],
  components: {pagination},
  data() {
    return {
      list: [],
      searchWay: "",
      keyWord: "",
      queryInfo: {
        pageNum: 1,
        pageSize: 5,
        orderNo:''
      },
      total: 0   
    };
  },
  computed: {},
  watch: {},
  methods: {
    async orderList() {
      const { data: res } = await orderList(
        `api/manage/order/list.do?pageSize=${this.queryInfo.pageSize}&pageNum=${this.queryInfo.pageNum}`
      );
      if (res.status !== 0) return this.$message.error("获取数据失败");
      this.list = res.data.list;
      this.total = res.data.total;
      this.$message.success("获取数据成功");
    },
    async search(){
        const { data: res } = await orderList(
        `api/manage/order/search.do?listType=search&pageSize=${this.queryInfo.pageSize}&pageNum=${this.queryInfo.pageNum}&${this.searchWay}=${this.queryInfo.orderNo}`
      );
      if (res.status !== 0) return this.$message.error("订单不存在");
      this.list = res.data.list;
      this.total = res.data.total;
      this.$message.success("获取数据成功");
    },
    check(info){
      this.$store.commit('defaultOrder',info)
      this.$router.push('/orderInfo')
    },
    changeNum(val){
      this.queryInfo.pageNum = val;
      this.orderList();
    },
    changeSize(val){
        this.queryInfo.pageSize = val
        this.orderList();
    }
  },
  beforeCreate() {},
  created() {},
  beforeMount() {},
  mounted() {
    this.orderList();
  }
};
</script> 
<style scoped>
</style>
